﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DFCLib;

namespace CW_Change_Type
{
    public partial class Form1 : Form
    {

        private IDfClientX m_DfClientX = null;
        private schemaDctm.ContentsDataTableDataTable m_contentsTable = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void m_exitMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void m_getObjsMenuItem_Click(object sender, EventArgs e)
        {
            String dqlStr = "select r_object_id, object_name from dm_document where i_contents_id is not null and i_cabinet_id = '[cabinet_id]'";

            //DEVELOPMENT:
            dqlStr = dqlStr.Replace("[cabinet_id]", "0c0008ae80000b37");

            m_DfClientX = new DfClientX();

            IDfSessionManager smgr = null;
            IDfClient client = null;
            IDfLoginInfo loginInfo = null;
            IDfQuery query = null;

            m_contentsTable = new schemaDctm.ContentsDataTableDataTable();


            try
            {
                client = m_DfClientX.getLocalClient();

                smgr = client.newSessionManager();
                loginInfo = m_DfClientX.getLoginInfo();
                loginInfo.setUser("your user");

                //DEVELOPMENT:
                loginInfo.setPassword("your password");


                smgr.setIdentity("DMS", loginInfo);

                IDfSession session = smgr.getSession("DMS");

                query = m_DfClientX.getQuery();
                query.setDQL(dqlStr);

                IDfCollection rs = query.execute(session, (int)tagDfQueryTypes.DF_READ_QUERY);

                int iColCount = rs.getAttrCount();

                while (rs.next())
                {
                    schemaDctm.ContentsDataTableRow row = m_contentsTable.NewContentsDataTableRow();
                    row.r_object_id = rs.getString("r_object_id");
                    row.object_name = rs.getString("object_name");
                    m_contentsTable.AddContentsDataTableRow(row);
                }

                m_dataGrid.DataSource = m_contentsTable;                

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
 
        }

        private void m_changeTypesMenuItem_Click(object sender, EventArgs e)
        {

                        m_DfClientX = new DfClientX();

            IDfSessionManager smgr = null;
            IDfClient client = null;
            IDfLoginInfo loginInfo = null;
            IDfQuery query = null;

            m_contentsTable = new schemaDctm.ContentsDataTableDataTable();


            try
            {
                client = m_DfClientX.getLocalClient();

                smgr = client.newSessionManager();
                loginInfo = m_DfClientX.getLoginInfo();
                loginInfo.setUser("your user");

                //DEVELOPMENT:
                loginInfo.setPassword("your password");

                //PRODUCTION:
                //loginInfo.setPassword("C@nwest");
                //loginInfo.setDomain("CA");

                smgr.setIdentity("DMS", loginInfo);

                IDfSession session = smgr.getSession("DMS");

                foreach (schemaDctm.ContentsDataTableRow row in m_contentsTable)
                {
                    String rObjectId = row.r_object_id;
                    IDfPersistentObject vdDocObj = session.newObject("vd_document");

                }


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }
    }
}
